project(kandas-l10n)
find_package(KDE4 REQUIRED)
find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)

if(NOT GETTEXT_MSGFMT_EXECUTABLE)
	message("NOTE: msgfmt not found. Translations will *not* be installed.")
else(NOT GETTEXT_MSGFMT_EXECUTABLE)
	SET(catalogname kandas)
	add_custom_target(translations ALL)
	file(GLOB PO_FILES ${catalogname}*.po)
	foreach(_poFile ${PO_FILES})
		get_filename_component(_poFileName ${_poFile} NAME)
		string(REGEX REPLACE "^${catalogname}_?" "" _langCode ${_poFileName})
		string(REGEX REPLACE "\\.po$" "" _langCode ${_langCode})
		if (_langCode)
			GET_FILENAME_COMPONENT(_lang ${_poFile} NAME_WE)
			SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
			ADD_CUSTOM_COMMAND(TARGET translations
				COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_poFile}
				DEPENDS ${_poFile})
			INSTALL(FILES ${_gmoFile} DESTINATION ${LOCALE_INSTALL_DIR}/${_langCode}/LC_MESSAGES/ RENAME ${catalogname}.mo)
		ENDIF (_langCode)
	ENDFOREACH (_poFile ${PO_FILES})
ENDIF(NOT GETTEXT_MSGFMT_EXECUTABLE)
